/**
 * long description for the file
 *
 * @summary short description for the file
 * @author xuesheng zhang
 *
 * Created at     : 2018-08-29 11:41:05 
 * Last modified  : 2018-09-18 17:37:07
 */


/* 合法uri*/
export const validateUR=(textval)=> {
  const urlregex = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
  return urlregex.test(textval)
}

/* 小写字母*/
export const validateLowerCase=(str)=>{
  const reg = /^[a-z]+$/
  return reg.test(str)
}

/* 大写字母*/
export const validateUpperCase=(str)=> {
  const reg = /^[A-Z]+$/
  return reg.test(str)
}

/* 大小写字母*/
export const validateAlphabets=(str)=> {
  const reg = /^[A-Za-z]+$/
  return reg.test(str)
}

/**
 * validate email
 * @param email
 * @returns {boolean}
 */
export const validateEmail=(email)=> {
  const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
  return re.test(email)
}

/**
 * validate phone
 * @param phone
 * @returns {boolean}
 */
export const validatePhone=(mobile)=> {
  const re = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/i;
  return re.test(mobile)
}

/**
 * validate Id numbe
 * @param Id numbe
 * @returns {boolean}
 */
export const validateIdnumber=(Idnumber)=> {
  const re = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
  return re.test(Idnumber)
}

/**
 * validate password level
 * @param password
 * @returns {number}
 */
export const validatePass=(mobile)=> {
  // 高
  const re = /"^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$"/;
  // 中
  const re1 = /^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$/;
  // 低
  const re2 = /(?=.{6,}).*/;
  if (re.test(mobile)) {
    return 3;
  }else if(re1.test(mobile)){
    return 2;
  }else if(re2.test(mobile)){
    return 1;
  }else{
    return 0;
  }
}

/**
 * validateSexNumr
 * @param number
 * @returns {boolean}
 */
export const validateSexNumr=(number)=> {
  const re = /^[\d\w\W]{6}$/;
  return re.test(number)
}


